package com.lp.business.dao;

import java.util.List;

import org.iframework.commons.domain.order.Order;
import org.iframework.commons.domain.pager.Pager;
import org.iframework.commons.util.fast.D;
import org.iframework.commons.util.fast.V;
import org.iframework.support.spring.hibernate.dao.BaseHibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.lp.business.model.Access;

/**
 * 权限控制
 * 
 * @author lipeng
 * 
 */
@Repository("accessDao")
public class AccessDao extends BaseHibernateDaoSupport<Access, String> {

	@Override
	public List<Access> findByModel(Access model, Order order, Pager pager) {
		model = model == null ? new Access() : model;
		StringBuilder hql = new StringBuilder();
		hql.append("from Access c where 1=1");
		hql.append(V.isNotEmpty(model.getId()) ? " and c.id=:id " : "");
		hql.append(V.isNotEmpty(model.getMenuId()) ? " and c.menuId=:menuId " : "");
		hql.append(V.isNotEmpty(model.getMenuMethodId()) ? " and c.menuMethodId=:menuMethodId " : "");
		hql.append(V.isNotEmpty(model.getRoleId()) ? " and c.roleId=:roleId " : "");
		hql.append(V.isNotEmpty(model.getUserId()) ? " and c.userId=:userId " : "");

		hql.append(V.isNotEmpty(model.getStatus()) ? " and c.status=:status " : "");
		hql.append(V.isNotEmpty(model.getDateStart()) ? " and c.createTime>'"+D.format(model.getDateStart(), "yyyy-MM-dd HH:mm:ss")+"'" : "");
		hql.append(V.isNotEmpty(model.getDateEnd()) ? " and c.createTime<'"+D.format(model.getDateEnd(), "yyyy-MM-dd HH:mm:ss")+"'" : "");
		
		hql.append(order != null ? order.toString() : "");
		return this.findByQueryString(hql.toString(), model, pager);
	}

}
